<?php
/**
 * Created by PhpStorm.
 * User: yu
 * Date: 2017/8/6
 * Time: 下午3:28
 */

namespace app\api\controller\v1;
use app\api\validate\IntCheck;
use app\lib\exception\BannerMissException;
use think\Exception;
use think\Request;
use app\api\model\Banner as BannerModel;
class Banner
{
	/**
	 * @param $id 那个地方的banner，目前只有首页
	 */
	public function getBanner($id){
		dump(input());die;

		(new IntCheck())->goCheck();

		$banner = BannerModel::getBannerById($id);
		if(!$banner){
			throw new BannerMissException();
//			throw new Exception('内部错误');
		}
		return $banner;
	}

	/**
	 * validate 验证讲解代码
	 */
	public function valid(Request $request){
		$data = [
			'name'=>'yuonly11111111',
			'email'=>'yuonlyqq.com'
		];
		//定义验证规则
//		$validate = new Validate(([
//			'name'=>'require|max:10',
//			'email'=>'email'
//		]));

		//执行验证
//		$result = $validate->check($data);
//		var_dump($result);
		//获取验证错误信息
//		echo $validate->getError();

		//批量验证
//		$result = $validate->batch()->check($data);
//
//		var_dump($result);
//		var_dump($validate->getError());

		//2 验证器的使用

//		$validate = new TestValidate();
//		$result = $validate->batch()->check($data);
//
//		var_dump($result);
//
//		var_dump($validate->getError());

		//3 自定义校验规则
//		$validate = new IntCheck();
//		$data = [
//			'id'=>$request->param('id')
//		];
//		$result = $validate->batch()->check($data);
//		var_dump($result);
//		var_dump($validate->getError());

		//4. 验证层
		(new IntCheck())->goCheck();

	}
}